$(".username input").on("input", function() {
  var $val = $(this).val();
  var size = $val.length;
  var text = "";
  var cls = "";
  if (size < 8) {
    text = "用户名长度不够";
    cls = "has-error";
  }
  if (size > 16) {
    text = "用户名太长了";
    cls = "has-error";
  }
  $(this).parent().addClass(cls);
  $(this).next().show()
});
